<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box1 {
        width: 300px;
        height: 300px;
        background-color: red;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 999;
      }
      .box2 {
        width: 320px;
        height: 320px;
        background-color: green;
        position: absolute;
        left: 0;
        top: 0;
      }
      .father1 {
        position: relative;
        z-index: 1;
      }
      .father2 {
        position: relative;
        z-index: 800;
      }
      /* z-index: 之前讲 只要设置了定位的元素 z-index足够大, 永远是在最上面显示
        如果父元素的层级很低(父元素设置了z-index), 即使子元素的z-index很大, 也不会在最上面显示
        (拼爹)
      */
    </style>
  </head>
  <body>
    <div class="father1"><div class="box1"></div></div>
    <div class="father2"><div class="box2"></div></div>
  </body>
</html>
